// 初始化vuex的子模块，定义路由配置的数据和修改路由配置的方法
import { asyncRoutes, constantRoutes } from '@/router'
export default {
  namespaced: true,
  state: {
    routes: [...constantRoutes]
  },
  mutations: {
    setRoutes(state, filterRoutes) {
      state.routes = [...constantRoutes, ...filterRoutes]
    },
    removeRoutes(state) {
      state.routes = [...constantRoutes]
    }

  },
  actions: {
    // 在子模块中过滤路由
    filterRoutes(context, menus) {
      const filterRoutes = asyncRoutes.filter(t => menus.includes(t.children[0].name))
      context.commit('setRoutes', filterRoutes)
      return filterRoutes
    }
  }
}
